<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="7" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <a-select 
              placeholder="搜索下拉"  
               v-model="queryParam.id"  
               show-search
               @search="handleChange($event)"
                option-filter-prop="children"
                :filter-option="filterOption"
               >
                <a-select-option   v-for="item in selectarr" :key="item.id">{{item.projectName}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="7" :lg="7" :md="8" :sm="24">
            <a-form-item label="创建时间">
              <a-range-picker
                  v-model="queryParam.created"
                  format="YYYY-MM-DD HH:mm:ss"
                  :placeholder="['开始时间', '结束时间']"
                  @change="onBirthdayChange"
                />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset('3')" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary">新建项目</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item2 key="1" @click="batchDel"><a-icon type="delete" />批量删除</a-menu-item2>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down"/></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定删除吗?" @confirm="() => handledelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">修改</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                  <a @click="detail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                  <a @click="detailFormOk(record,'2')">分享</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <Project-modal ref="modalForm" @ok="modalFormOk"></Project-modal>
    <Project-detail  ref="detailForm" @ok="detailFormOk"></Project-detail>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import ProjectModal from './modules/ProjectModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction,deleteAction } from '../../../api/manage'
import ProjectDetail from './modules/ProjectDetail'
export default {
  name: 'BusTreviRiverPcList',
  mixins: [JeecgListMixin],
  components: {
    ProjectModal,
    ProjectDetail
  },
  data() {
    return {
      description: '项目管理',
      // 表头
      columns: [
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName'
        },
        {
          title: '文件夹数量(个)',
          align: 'center',
          dataIndex: 'folderNumber'
        },
        {
          title: '文件数量(个)',
          align: 'center',
          dataIndex: 'fileNumber'
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createdDate'
        },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'creator'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      dataSource: [
        {
          createBy: '1111'
        }
      ],
      url: {
        list: `/bus/busProject/list?creator=${localStorage.getItem('userid')}`,
        delete: "/bus/busProject/delete",
        deleteBatch: "/sensitiveWord/busSensitiveWord/deleteBatch",
        projectNameList:'/bus/busProject/projectNameList'
      },
      selectarr:[]
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  mounted(){
    this.selectlist()
  },
  methods: {
  
    //选中创建时间
    onBirthdayChange(value, dateString) {
      this.queryParam.startDate = dateString[0]
      this.queryParam.endDate = dateString[1]
    },
    //项目名称下拉
    selectlist(e){
      const httpurl = this.url.projectNameList
      const params = {
        projectName:e
      }
      getAction(httpurl,params).then((res)=>{
        this.selectarr = res.result
      })
    },
    handleChange(e)
    {
      this.selectlist(e)
    },
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    //删除
    handledelete(id){
      const httpurl = this.url.delete
        
       deleteAction(httpurl,{id:id}).then((res)=>{
        if(res.code == 200)
        {
          this.$message.success(res.message)
          this.loadData();
        }else
        {
          this.$message.error(res.message)
        }
       })
    },
    //详情
    detail(record)
    {
      console.log(record,'record');
      this.$router.push({path:`/resourcesys/Sharedetail?id=${record.id}`})
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
